<!--
  // Creation History
  // --------------------------------------------------------------
  //	Company:			HTHK
  //	NAME:				TimeSheetCheck.jsp
  //	TITLE:				TimeSheet Checking
  //	FUNCTION:			check if Staff ID of the login user is in table TSS_C_EMPLOYEE.
  //	BY:					Jet Tao
  //	DATE:				11/12/2003
  // --------------------------------------------------------------
-->
<%@ page import="com.ffpc.sql.*"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="admin.*" %>

<%

	boolean debug =false;
		
if(debug)
{
	System.out.println("---------- TimeSheetCheck.jsp create connection...... ---------");
}
	ConnectionFactory connectionFactory = new ConnectionFactory("fasp_tss");
if(debug)
{
	System.out.println(connectionFactory.toString());
}

    Connection con = (Connection)connectionFactory.getConnection();
    User user = (User)session.getAttribute("user");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd",Locale.US);
	String today=sdf.format(new java.util.Date());
	String staff_id=null;
	ResultSet rs=null;
	Statement stmt=null;
	boolean isSuccess=false;
    String sql=" Select a.staff_no"+
			 " from TSS.TSS_C_EMPLOYEE a"+
			 " where a.staff_no='"+user.getStaff_id()+"'";
	
//	System.out.println("today="+today);
//	System.out.println("staff_no="+user.getStaff_id());
	try
	{
		stmt=con.createStatement();
		rs=stmt.executeQuery(sql);
		if(rs.next())
		{
			System.out.println("congratulation, your Staff ID has authorization to maintenance timesheet.");
//			System.out.println("user_id="+rs.getString(1));
//			System.out.println("staff_id="+rs.getString(2));
			staff_id=rs.getString(1);
			isSuccess=true;
		}
		else
		{
			System.out.println("Sorry, your Staff ID has not authorization to maintenance timesheet.");
			isSuccess=false;
		}
	}
	catch(SQLException sqle)
	{
		isSuccess=false;
		System.out.println(sqle.getMessage());
	}
	finally
	{
		if(rs!=null)
			rs.close();
		if(stmt!=null)
			stmt.close();
			
		connectionFactory.finalize();
if(debug)
{
	System.out.println("---------- TimeSheetCheck.jsp free connection...... ---------");
	System.out.println(connectionFactory.toString());
}

	}

	if(!isSuccess)
	{

%>
		<jsp:forward page='TimeSheetWarning.jsp' />
<%
	} 
	else
	{
//	System.out.println("Success11111111111="+isSuccess);
%>
		<jsp:forward page="/servlet/tss.timesheet.TimeSheetInput">
		<jsp:param name="selected_date" value="<%=today%>" />
		<jsp:param name="staff_no" value="<%=staff_id%>" />
		<jsp:param name="which_week" value="1" />
		<jsp:param name="operation_type" value="edit" />
		<jsp:param name="now_date" value="<%=today%>" />
		</jsp:forward> 
<%
	}
%>
